<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('generar_pdf'))
    {
   function generar_pdf($arrHeading,$arrData,$sTitulo){
       if(!is_array($arrHeading) or !is_array($arrData)){
         return 0;
        }
    $sTitulo = empty($sTitulo) ? 'NO SE HA DEFINIDO EL TITULO..' : $sTitulo;
    $CI =& get_instance();
    $CI->load->library('table');
    $tmpl = array('table_open' => '<table border="0" cellpadding="2" cellspacing="1">'); 
    $CI->table->set_template($tmpl); 
    $CI->table->set_heading($arrHeading);

$html = "<html><head> <style> h1{ font-family: times new roman; font-size: 24px; text-align:center; } table { color: #fff;  font-family: Arial Black; font-size: 12px; background-color: #B10020; border: red 0px solid; } table td { font-weight: none; color: #000; background-color: #FAFAFA; font-size: 12px; font-family: times new roman; } </style> </head><body><h1>$sTitulo</h1>";

 $html .= $CI->table->generate($arrData); 
 $html .= '</body></html>';
 
 if(ob_get_contents()){
  ob_end_clean();
 }
 require_once('./plugins/examples/lang/spa.php');
 require_once('./plugins/tcpdf.php');
 
 $pdf = new TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false); 
 $pdf->SetCreator(PDF_CREATOR); 
 $pdf->SetAuthor('Morcillo/Gutierrez'); 
 $pdf->SetTitle($sTitulo); 
 $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001'); 
 $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 
 $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); 
 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 
 $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 
 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 
 $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 
 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 
 $pdf->setLanguageArray($l); 
 $pdf->setFontSubsetting(true); 
 $pdf->SetFont('dejavusans', '', 12, '', true); 
 $pdf->AddPage(); 
 $pdf->writeHTML($html, true, false, true, false, ''); 
 $pdf->Output('','D'); } 
 
 }

